from fastapi import APIRouter
from models.users import User
from schemas.users import UserInfo

router_user = APIRouter(prefix='/user', tags=['用户接口'])


@router_user.get('/', summary="获取用户列表")
async def get_user_list(page: int, limit: int):
    """分页查询列表"""
    item = await User.filter().offset(page * limit).limit(limit)
    return item


@router_user.get('/{user_id}', summary="获取用户详情")
async def get_user_detail(user_id: int):
    """分页查询列表"""
    item = await User.get_or_none(id=user_id)
    return item


@router_user.post('/', summary="增加用户")
async def add_user_detail(item: UserInfo):
    """分页查询列表"""
    item = await User.create(id=item.id,
                             name=item.name,
                             nickName=item.nickName,
                             gender=item.gender,
                             avatar=item.avatar,
                             address=item.address,
                             email=item.email,
                             password=item.password,
                             enable=item.enable,
                             is_deleted=item.is_deleted
                             )
    return item
